import { Application } from "mydog";
import { RoomMgr } from "../../../app/svr_game/roomMgr";
import { svr_game } from "../../../app/svr_game/svr_game";
import {I_playerEnter, Player} from "../../../app/svr_game/player";
import {changeConGameState, changeInfoGameState} from "../../../app/util/gameUtil";

declare global {
    interface Rpc {
        game: {
            main: Remote,
        }
    }
}

export default class Remote {
    private roomMgr: RoomMgr;
    constructor(app: Application) {
        this.roomMgr = svr_game.roomMgr;
    }

    // 掉线
    offline(tableId: number, uid: number) {
        this.roomMgr.leave(tableId,uid);
    }

    enter(playerEnter: I_playerEnter, cb: (err: number) => void) {
        if(this.roomMgr.enter(playerEnter)){
            cb(0);
        }else{
            cb(1);
        }
    }

    relink(tableId: number, info: { "uid": number, "sid": string }, cb: (err: number, ok: boolean) => void) {
        let table = this.roomMgr.getTable(tableId);
        if (!table) {
            return cb(0, false);
        }
        let ok = table.relink(info);
        cb(0, ok);
    }
}